package com.binc.testspring.study.mina.study2;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

import java.nio.charset.Charset;

/**
 * FileName: MyProtocolFactory  自定义编解码工厂
 * Autho: binC
 * Date:  2022/3/25 17:16
 */
public class MyProtocolFactory implements ProtocolCodecFactory {
    private final MyProtocolDecoder decoder;
    private final MyProtocolEncoder encoder;

    public MyProtocolFactory(Charset charset) {
        decoder = new MyProtocolDecoder(charset);
        encoder = new MyProtocolEncoder(charset);
    }

    @Override
    public ProtocolEncoder getEncoder(IoSession ioSession) throws Exception {
        return encoder;
    }

    @Override
    public ProtocolDecoder getDecoder(IoSession ioSession) throws Exception {
        return decoder;
    }
}
